package edu.jvn.ts.util;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.util.Random;

public class SimulationFileGeneration {

	public void generateSimulationFile(String fileName) {
		try {
			//Constant value
			int minValue = 0;
			int maxValue = 80;
			int n = 360;
			
			// Declare Simulation File Generation Data
			SimulationFileGeneration smg = new SimulationFileGeneration();
			int[] simulationData = smg.random(minValue, maxValue, n);
			
			//Write Simulation data to file
			if (simulationData != null) {
				FileWriter fstream = new FileWriter(fileName);
				if (fstream != null) {
					BufferedWriter out = new BufferedWriter(fstream);
					for (int i = 0; i < n; i++) {
						out.write(simulationData[i] + " ");
					}
					// Close the output stream
					out.close();
				}
			}
		} catch (Exception e) {// Catch exception if any
			System.err.println("Error: " + e.getMessage());
		}
	}

	/*
	 * Random number for simulation
	 */
	public int[] random(int minValue, int maxValue, int n) {
		int[] returnValue = new int[n];
		for (int i = 0; i < n; i++) {
			int randomNum = minValue + (int) (Math.random() * maxValue);
			returnValue[i] = randomNum;
		}
		return returnValue;
	}

	public static void main(String[] args) {
		int n = 100;
		int[] testArr = new int[n];
		SimulationFileGeneration smg = new SimulationFileGeneration();
		testArr = smg.random(0, 80, n);
		for (int i = 0; i < n; i++) {
			System.out.println(testArr[i] + " ");
		}
		
		smg.generateSimulationFile("ts.txt");

	}

}
